home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 2 / Atari Mega Archive CD - Volume 2.iso / minix / up1510b.tgz / up1510b / src / test / test3.c < prev    next >
C/C++ Source or Header  |  1990-07-23  |  2KB  |  127 lines

  1. /* test 3 */
  2.  
  3. #include <signal.h>
  4. #include <stdio.h>
  5.  
  6. int is, array[4];
  7. int parsigs, parpid, parcum;
  8. int sigct, cumsig, errct;
  9.  
  10. main()
  11. {
  12.   int i;
  13.  
  14.   printf("Test  3 ");
  15.   fflush(stdout);        /* have to flush for child's benefit */
  16.  
  17.   for (i = 0; i < 9; i++) {
  18.     test91();
  19.     test92();
  20.   }
  21.   if (cumsig != 9) e(3);
  22.   if (errct == 0)
  23.     printf("ok\n");
  24.   else
  25.     printf("%d errors\n", errct);
  26. }
  27.  
  28.  
  29. test90()
  30. {
  31.   extern catch();
  32.  
  33.   int n, pid;
  34.  
  35.   parpid = getpid();
  36.   signal(10, catch);
  37.  
  38.   if (pid = fork()) {
  39.     while (parsigs == 0);
  40.     if (kill(pid, 9) < 0) e(1);
  41.     wait(&n);
  42.     if (n != 9) e(2);
  43.   } else {
  44.     kill(parpid, 10);
  45.     pause();
  46.   }
  47. }
  48.  
  49.  
  50. catch()
  51. {
  52.   parsigs++;
  53.   parcum++;
  54. }
  55.  
  56. e(n)
  57. int n;
  58. {
  59.   printf("Error %d  ", n);
  60.   errct++;
  61.   perror("");
  62. }
  63.  
  64.  
  65. test91()
  66. {
  67.   int fd[2], n, sigpip();
  68.   char buf[4];
  69.  
  70.   sigct = 0;
  71.   signal(SIGPIPE, sigpip);
  72.   pipe(fd);
  73.   if (fork()) {
  74.     /* Parent */
  75.     close(fd[0]);
  76.     while (sigct == 0) {
  77.         write(fd[1], buf, 1);
  78.     }
  79.     wait(&n);
  80.   } else {
  81.     /* Child */
  82.     close(fd[0]);
  83.     close(fd[1]);
  84.     exit(0);
  85.   }
  86. }
  87.  
  88. sigpip()
  89. {
  90.   sigct++;
  91.   cumsig++;
  92. }
  93.  
  94.  
  95. test92()
  96. {
  97.   int pid, n;
  98.  
  99.   signal(SIGINT, SIG_DFL);
  100.   is = 0;
  101.   if ((array[is++] = fork()) > 0) {
  102.     if ((array[is++] = fork()) > 0) {
  103.         if ((array[is++] = fork()) > 0) {
  104.             if ((array[is++] = fork()) > 0) {
  105.                 signal(SIGINT, SIG_IGN);
  106.                 kill(array[0], SIGINT);
  107.                 kill(array[1], SIGINT);
  108.                 kill(array[2], SIGINT);
  109.                 kill(array[3], SIGINT);
  110.                 wait(&n);
  111.                 wait(&n);
  112.                 wait(&n);
  113.                 wait(&n);
  114.             } else {
  115.                 pause();
  116.             }
  117.         } else {
  118.             pause();
  119.         }
  120.     } else {
  121.         pause();
  122.     }
  123.   } else {
  124.     pause();
  125.   }
  126. }
  127.